﻿using DongFangGuoKai.TaskPlatform.Commn.Attributes;
using DongFangGuoKai.TaskPlatform.Commn.LogModule;
using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace DongFangGuoKai.TaskPlatform.Job
{
    [Job("测试Job名字", "测试Job组名", "每两秒调用一次")]
    public class DemoJob : IJob
    {

        static int Count = 0;
        public LogHelper<DemoJob> _log { get; set; }

        public async Task Execute(IJobExecutionContext context)
        {
            Count++;

            if (Count == 10)
            {

                Type type = this.GetType();
                string key = string.Empty;
                string group = string.Empty;
                if (type.IsDefined(typeof(JobAttribute), true))
                {
                    JobAttribute attribute = type.GetCustomAttribute<JobAttribute>();
                    key = attribute.JobKey;
                    group = attribute.JobGroup;
                }

                var scheduler = context.Scheduler;
                JobKey jobKey = new JobKey(key, group);

                //执行Job
                scheduler.PauseJob(jobKey);
                //重置为0  
                Count = 0;
                //发送邮件

                _log.LogSuc(null, "停止Job");
            }
            _log.LogSuc(null, Count.ToString());


            await Task.CompletedTask;
        }
    }
}
